//
//  MultiSelectCell.m
//  MultSeletedRows
//
//  Created by tangxp on 27/12/12.
//  Copyright (c) 2012 tangxp. All rights reserved.
//

#import "MultiSelectCell.h"

@implementation MultiSelectCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, 320, 44)];
		label.textColor = [UIColor blackColor];
		label.backgroundColor = [UIColor clearColor];
		label.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
		[self.contentView addSubview:label];
        self.tLabel = label;
        
        UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"NotSelected.png" ]];
        imgView.frame = CGRectMake(-30, 8, 30, 30);
        [self.contentView addSubview:imgView];
        self.tImageView = imgView;
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
	[self setNeedsLayout];
}

- (void)layoutSubviews
{
    if (self.selected) {
        _tImageView.image = [UIImage imageNamed:@"IsSelected.png"];
    }
    else {
        _tImageView.image = [UIImage imageNamed:@"NotSelected.png"];
    }
	[UIView beginAnimations:nil context:nil];
	[UIView setAnimationBeginsFromCurrentState:YES];
    
	[super layoutSubviews];
    
	if (((UITableView *)self.superview).isEditing)
	{
		CGRect contentFrame = self.contentView.frame;
		contentFrame.origin.x = 35;
		self.contentView.frame = contentFrame;
	}
	else
	{
		CGRect contentFrame = self.contentView.frame;
		contentFrame.origin.x = 0;
		self.contentView.frame = contentFrame;
	}
    
	[UIView commitAnimations];
}

@end
